package com.loan.market.util

import java.text.SimpleDateFormat
import java.util.Locale

fun Long.toDayTime(): Long {
    return formatTime("dd-MM-yyyy").toTimeStamp("dd-MM-yyyy")
}

fun Long.formatTime(format: String = "dd-MM-yyyy"): String {
    if (this == Long.MAX_VALUE) return ""
    return SimpleDateFormat(format, Locale("es", "ar")).format(this)
}

fun String.toTimeStamp(format: String = "dd-MM-yyyy"): Long {
    return runCatching {
        SimpleDateFormat(format, Locale("es", "ar")).parse(this)?.time ?: Long.MAX_VALUE
    }.getOrElse {
        Long.MAX_VALUE
    }
}